<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>CPP11ThreadPool: thread.hpp 源文件</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="CPP.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">CPP11ThreadPool
   </div>
   <div id="projectbrief">C++11线程池</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'搜索');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','搜索');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">thread.hpp</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#ifndef THREAD_HPP</span></div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="preprocessor">#define THREAD_HPP</span></div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;</div><div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="preprocessor">#include &lt;atomic&gt;</span></div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="preprocessor">#include &lt;chrono&gt;</span></div><div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="preprocessor">#include &lt;cstring&gt;</span></div><div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="preprocessor">#include &lt;memory&gt;</span></div><div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="preprocessor">#include &lt;string&gt;</span></div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="preprocessor">#include &lt;thread&gt;</span></div><div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;</div><div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="preprocessor">#include &lt;sys/syscall.h&gt;</span></div><div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="preprocessor">#include &lt;sys/signal.h&gt;</span></div><div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="preprocessor">#include &lt;unistd.h&gt;</span></div><div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;</div><div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="preprocessor">#include &quot;functor_wrapper.hpp&quot;</span></div><div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;</div><div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="keyword">static</span> pthread_t stdTidToPthreadId(std::thread::id tid) {</div><div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;    static_assert(</div><div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;        std::is_same&lt;pthread_t, std::thread::native_handle_type&gt;::value,</div><div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;        <span class="stringliteral">&quot;This assumes that the native handle type is pthread_t&quot;</span>);</div><div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;    static_assert(</div><div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;        <span class="keyword">sizeof</span>(std::thread::native_handle_type) == <span class="keyword">sizeof</span>(std::thread::id),</div><div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;        <span class="stringliteral">&quot;This assumes std::thread::id is a thin wrapper around &quot;</span></div><div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;        <span class="stringliteral">&quot;std::thread::native_handle_type, but that doesn&#39;t appear to be true.&quot;</span>);</div><div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;    <span class="comment">// In most implementations, std::thread::id is a thin wrapper around</span></div><div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;    <span class="comment">// std::thread::native_handle_type, which means we can do unsafe things to</span></div><div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;    <span class="comment">// extract it.</span></div><div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;    pthread_t id;</div><div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;    std::memcpy(&amp;<span class="keywordtype">id</span>, &amp;tid, <span class="keyword">sizeof</span>(<span class="keywordtype">id</span>));</div><div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;    <span class="keywordflow">return</span> id;</div><div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;}</div><div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;</div><div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;<span class="keyword">static</span> std::string getThreadName(std::thread::id <span class="keywordtype">id</span>) {</div><div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;    std::array&lt;char, 16&gt; buf;</div><div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;    <span class="keywordflow">if</span> (<span class="keywordtype">id</span> != std::thread::id() &amp;&amp;</div><div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;            pthread_getname_np(stdTidToPthreadId(<span class="keywordtype">id</span>), buf.data(), buf.size()) == 0) {</div><div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;        <span class="keywordflow">return</span> std::string(buf.data());</div><div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;    } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;        <span class="keywordflow">return</span> <span class="stringliteral">&quot;&quot;</span>;</div><div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;    }</div><div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;}</div><div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;</div><div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;<span class="keyword">static</span> std::string getCurrentThreadName() {</div><div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;    <span class="keywordflow">return</span> getThreadName(std::this_thread::get_id());</div><div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;}</div><div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;</div><div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;<span class="keyword">static</span> <span class="keywordtype">bool</span> setThreadName(std::thread::id tid, <span class="keyword">const</span> std::string&amp; name) {</div><div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;    <span class="keyword">auto</span> str = name.substr(0, 15);</div><div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;    <span class="keywordtype">char</span> buf[16] = {};</div><div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;    std::memcpy(buf, str.data(), str.size());</div><div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;    <span class="keyword">auto</span> <span class="keywordtype">id</span> = stdTidToPthreadId(tid);</div><div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;    <span class="keywordflow">return</span> 0 == pthread_setname_np(<span class="keywordtype">id</span>, buf);</div><div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;}</div><div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;</div><div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;<span class="keyword">static</span> <span class="keywordtype">bool</span> setThreadName(pthread_t pid, <span class="keyword">const</span> std::string&amp; name) {</div><div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;    static_assert(</div><div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;        std::is_same&lt;pthread_t, std::thread::native_handle_type&gt;::value,</div><div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;        <span class="stringliteral">&quot;This assumes that the native handle type is pthread_t&quot;</span>);</div><div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;    static_assert(</div><div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;        <span class="keyword">sizeof</span>(std::thread::native_handle_type) == <span class="keyword">sizeof</span>(std::thread::id),</div><div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;        <span class="stringliteral">&quot;This assumes std::thread::id is a thin wrapper around &quot;</span></div><div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;        <span class="stringliteral">&quot;std::thread::native_handle_type, but that doesn&#39;t appear to be true.&quot;</span>);</div><div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;    <span class="comment">// In most implementations, std::thread::id is a thin wrapper around</span></div><div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;    <span class="comment">// std::thread::native_handle_type, which means we can do unsafe things to</span></div><div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;    <span class="comment">// extract it.</span></div><div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;    std::thread::id id;</div><div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;    std::memcpy(static_cast&lt;void*&gt;(&amp;<span class="keywordtype">id</span>), &amp;pid, <span class="keyword">sizeof</span>(<span class="keywordtype">id</span>));</div><div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;    <span class="keywordflow">return</span> setThreadName(<span class="keywordtype">id</span>, name);</div><div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;}</div><div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;</div><div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;<span class="keyword">static</span> <span class="keywordtype">bool</span> setCurrentThreadName(<span class="keyword">const</span> std::string&amp; name) {</div><div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;    <span class="keywordflow">return</span> setThreadName(std::this_thread::get_id(), name);</div><div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;}</div><div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;</div><div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;<span class="keyword">class </span><a class="code" href="classThreadPoolExecutor.html">ThreadPoolExecutor</a>;</div><div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;</div><div class="line"><a name="l00122"></a><span class="lineno"><a class="line" href="classThread.html">  122</a></span>&#160;<span class="keyword">class </span><a class="code" href="classThread.html">Thread</a> {</div><div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;    <span class="keyword">public</span>:</div><div class="line"><a name="l00127"></a><span class="lineno"><a class="line" href="classThread.html#a430059e402325caaf1ed185fb520c9d2">  127</a></span>&#160;        <span class="keyword">using</span> <a class="code" href="classThread.html#a430059e402325caaf1ed185fb520c9d2">sptr</a> = std::shared_ptr&lt;Thread&gt;;</div><div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;</div><div class="line"><a name="l00134"></a><span class="lineno"><a class="line" href="classThread.html#a66350772ff3af06962db113658a72ae3">  134</a></span>&#160;        <a class="code" href="classThread.html#a66350772ff3af06962db113658a72ae3">Thread</a>(<span class="keywordtype">int</span> pro): <a class="code" href="classThread.html#ada8c342b34fb001cfcf57619b7150840">prio_</a>(pro) {}</div><div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;</div><div class="line"><a name="l00142"></a><span class="lineno"><a class="line" href="classThread.html#a038819a1ef7bb4e50ae580d477f1a3b0">  142</a></span>&#160;        <a class="code" href="classThread.html#a038819a1ef7bb4e50ae580d477f1a3b0">Thread</a>(<span class="keyword">const</span> std::string&amp; name = <span class="stringliteral">&quot;&quot;</span>, <span class="keywordtype">int</span> pro = 20)</div><div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;            : <a class="code" href="classThread.html#ada8c342b34fb001cfcf57619b7150840">prio_</a>(pro), <a class="code" href="classThread.html#aa222eb32e5fc8f386d9fb018607acd9c">name_</a>(name) {}</div><div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;</div><div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;        <span class="keyword">template</span>&lt;<span class="keyword">typename</span> FunctionType&gt;</div><div class="line"><a name="l00153"></a><span class="lineno"><a class="line" href="classThread.html#a61efca5f0beb62628c515fb7cdef7e08">  153</a></span>&#160;        <a class="code" href="classThread.html#a61efca5f0beb62628c515fb7cdef7e08">Thread</a>(FunctionType f, <span class="keyword">const</span> std::string&amp; name = <span class="stringliteral">&quot;&quot;</span>, <span class="keywordtype">int</span> pro = 20)</div><div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;            : <a class="code" href="classThread.html#ada8c342b34fb001cfcf57619b7150840">prio_</a>(pro), <a class="code" href="classThread.html#aa222eb32e5fc8f386d9fb018607acd9c">name_</a>(name), <a class="code" href="classThread.html#a4cf09d1f62096dd4aed7a3ee06212b81">func_uptr_</a>(new <a class="code" href="structFunctor__t.html">Functor_t</a>&lt;FunctionType&gt;(std::move(f))) {}</div><div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;</div><div class="line"><a name="l00159"></a><span class="lineno"><a class="line" href="classThread.html#a026b23628e1727050e864e00489c0baf">  159</a></span>&#160;        <span class="keyword">virtual</span> <a class="code" href="classThread.html#a026b23628e1727050e864e00489c0baf">~Thread</a>() {</div><div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;            <span class="keywordflow">if</span> (<a class="code" href="classThread.html#ad313ba812a7875c743dd0d37d565acfb">thread_</a>.joinable()) {</div><div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;                <a class="code" href="classThread.html#ad313ba812a7875c743dd0d37d565acfb">thread_</a>.join();</div><div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;            }</div><div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;        }</div><div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;</div><div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;    <span class="keyword">protected</span>:</div><div class="line"><a name="l00169"></a><span class="lineno"><a class="line" href="classThread.html#a7574ff300357f9d3193db03b83937eac">  169</a></span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classThread.html#a7574ff300357f9d3193db03b83937eac">run</a>() {}</div><div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;</div><div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160;    <span class="keyword">private</span>:</div><div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> executeRun() <span class="keyword">final</span> {</div><div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;            setCurrentThreadName(<a class="code" href="classThread.html#aa222eb32e5fc8f386d9fb018607acd9c">name_</a> + std::to_string(syscall(__NR_gettid)));</div><div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;            <a class="code" href="classThread.html#a0c0878a96696bbb092a69bc2f1f812fd">currentPid_</a> = syscall(__NR_gettid);</div><div class="line"><a name="l00178"></a><span class="lineno">  178</span>&#160;            <a class="code" href="classThread.html#a13aa04a60328060dec3a25b286c933a2">idle_</a>.store(<span class="keyword">false</span>, std::memory_order_relaxed);</div><div class="line"><a name="l00179"></a><span class="lineno">  179</span>&#160;            <a class="code" href="classThread.html#ae7ed71c6b1f7782ecd4186005fd70760">lastActiveTime_</a> = std::chrono::steady_clock::now();</div><div class="line"><a name="l00180"></a><span class="lineno">  180</span>&#160;            pthread_setschedprio(pthread_self(), <a class="code" href="classThread.html#ada8c342b34fb001cfcf57619b7150840">prio_</a>);</div><div class="line"><a name="l00181"></a><span class="lineno">  181</span>&#160;            <span class="keywordflow">try</span> {</div><div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;                <a class="code" href="classThread.html#a7574ff300357f9d3193db03b83937eac">run</a>();</div><div class="line"><a name="l00183"></a><span class="lineno">  183</span>&#160;            } <span class="keywordflow">catch</span>(...) {</div><div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160;                <a class="code" href="classThread.html#a13aa04a60328060dec3a25b286c933a2">idle_</a>.store(<span class="keyword">true</span>, std::memory_order_relaxed);</div><div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160;                <span class="keywordflow">throw</span>;</div><div class="line"><a name="l00186"></a><span class="lineno">  186</span>&#160;            }</div><div class="line"><a name="l00187"></a><span class="lineno">  187</span>&#160;            <a class="code" href="classThread.html#a13aa04a60328060dec3a25b286c933a2">idle_</a>.store(<span class="keyword">true</span>, std::memory_order_relaxed);</div><div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160;        }</div><div class="line"><a name="l00189"></a><span class="lineno">  189</span>&#160;</div><div class="line"><a name="l00193"></a><span class="lineno">  193</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> executeFunc() <span class="keyword">final</span> {</div><div class="line"><a name="l00194"></a><span class="lineno">  194</span>&#160;            setCurrentThreadName(<a class="code" href="classThread.html#aa222eb32e5fc8f386d9fb018607acd9c">name_</a> + std::to_string(syscall(__NR_gettid)));</div><div class="line"><a name="l00195"></a><span class="lineno">  195</span>&#160;            <a class="code" href="classThread.html#a0c0878a96696bbb092a69bc2f1f812fd">currentPid_</a> = syscall(__NR_gettid);</div><div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;            <a class="code" href="classThread.html#a13aa04a60328060dec3a25b286c933a2">idle_</a>.store(<span class="keyword">false</span>, std::memory_order_relaxed);</div><div class="line"><a name="l00197"></a><span class="lineno">  197</span>&#160;            <a class="code" href="classThread.html#ae7ed71c6b1f7782ecd4186005fd70760">lastActiveTime_</a> = std::chrono::steady_clock::now();</div><div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;            pthread_setschedprio(pthread_self(), <a class="code" href="classThread.html#ada8c342b34fb001cfcf57619b7150840">prio_</a>);</div><div class="line"><a name="l00199"></a><span class="lineno">  199</span>&#160;            <span class="keywordflow">try</span> {</div><div class="line"><a name="l00200"></a><span class="lineno">  200</span>&#160;                <a class="code" href="classThread.html#a4cf09d1f62096dd4aed7a3ee06212b81">func_uptr_</a>-&gt;call();</div><div class="line"><a name="l00201"></a><span class="lineno">  201</span>&#160;                <a class="code" href="classThread.html#a4cf09d1f62096dd4aed7a3ee06212b81">func_uptr_</a>.release();</div><div class="line"><a name="l00202"></a><span class="lineno">  202</span>&#160;            } <span class="keywordflow">catch</span>(...) {</div><div class="line"><a name="l00203"></a><span class="lineno">  203</span>&#160;                <a class="code" href="classThread.html#a13aa04a60328060dec3a25b286c933a2">idle_</a>.store(<span class="keyword">true</span>, std::memory_order_relaxed);</div><div class="line"><a name="l00204"></a><span class="lineno">  204</span>&#160;                <span class="keywordflow">throw</span>;</div><div class="line"><a name="l00205"></a><span class="lineno">  205</span>&#160;            }</div><div class="line"><a name="l00206"></a><span class="lineno">  206</span>&#160;            <a class="code" href="classThread.html#a13aa04a60328060dec3a25b286c933a2">idle_</a>.store(<span class="keyword">true</span>, std::memory_order_relaxed);</div><div class="line"><a name="l00207"></a><span class="lineno">  207</span>&#160;        }</div><div class="line"><a name="l00208"></a><span class="lineno">  208</span>&#160;</div><div class="line"><a name="l00209"></a><span class="lineno">  209</span>&#160;    <span class="keyword">public</span>:</div><div class="line"><a name="l00214"></a><span class="lineno"><a class="line" href="classThread.html#a3a36451e02a15180624cdd88212cb1ba">  214</a></span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classThread.html#a3a36451e02a15180624cdd88212cb1ba">start</a>() final {</div><div class="line"><a name="l00215"></a><span class="lineno">  215</span>&#160;            <span class="keywordflow">if</span> (!<a class="code" href="classThread.html#a091bdad0a084b3f2c659f8cdd5369d53">stop_</a>.load(std::memory_order_relaxed))</div><div class="line"><a name="l00216"></a><span class="lineno">  216</span>&#160;                <span class="keywordflow">throw</span> std::logic_error(<span class="stringliteral">&quot;thread already started&quot;</span>);</div><div class="line"><a name="l00217"></a><span class="lineno">  217</span>&#160;            <a class="code" href="classThread.html#a091bdad0a084b3f2c659f8cdd5369d53">stop_</a>.store(<span class="keyword">false</span>, std::memory_order_relaxed);</div><div class="line"><a name="l00218"></a><span class="lineno">  218</span>&#160;            <a class="code" href="classThread.html#ad313ba812a7875c743dd0d37d565acfb">thread_</a> = std::thread([<span class="keyword">this</span>]() {</div><div class="line"><a name="l00219"></a><span class="lineno">  219</span>&#160;                <span class="keywordflow">if</span> (<a class="code" href="classThread.html#a535df3b8fc4ff9ca48f5a6d561162a36">yield_</a>) {</div><div class="line"><a name="l00220"></a><span class="lineno">  220</span>&#160;                    std::this_thread::yield();</div><div class="line"><a name="l00221"></a><span class="lineno">  221</span>&#160;                    <a class="code" href="classThread.html#a535df3b8fc4ff9ca48f5a6d561162a36">yield_</a> = <span class="keyword">false</span>;</div><div class="line"><a name="l00222"></a><span class="lineno">  222</span>&#160;                }</div><div class="line"><a name="l00223"></a><span class="lineno">  223</span>&#160;                <span class="keywordflow">if</span> (<a class="code" href="classThread.html#a4cf09d1f62096dd4aed7a3ee06212b81">func_uptr_</a> != <span class="keyword">nullptr</span>) {</div><div class="line"><a name="l00224"></a><span class="lineno">  224</span>&#160;                    executeFunc();</div><div class="line"><a name="l00225"></a><span class="lineno">  225</span>&#160;                } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00226"></a><span class="lineno">  226</span>&#160;                    executeRun();</div><div class="line"><a name="l00227"></a><span class="lineno">  227</span>&#160;                }</div><div class="line"><a name="l00228"></a><span class="lineno">  228</span>&#160;                <a class="code" href="classThread.html#a0c0878a96696bbb092a69bc2f1f812fd">currentPid_</a> = -1;</div><div class="line"><a name="l00229"></a><span class="lineno">  229</span>&#160;            });</div><div class="line"><a name="l00230"></a><span class="lineno">  230</span>&#160;        }</div><div class="line"><a name="l00231"></a><span class="lineno">  231</span>&#160;</div><div class="line"><a name="l00235"></a><span class="lineno"><a class="line" href="classThread.html#a07b23d8d75300651cba3eb79652c77fd">  235</a></span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classThread.html#a07b23d8d75300651cba3eb79652c77fd">join</a>() final {</div><div class="line"><a name="l00236"></a><span class="lineno">  236</span>&#160;            <a class="code" href="classThread.html#ad313ba812a7875c743dd0d37d565acfb">thread_</a>.join();</div><div class="line"><a name="l00237"></a><span class="lineno">  237</span>&#160;        }</div><div class="line"><a name="l00238"></a><span class="lineno">  238</span>&#160;</div><div class="line"><a name="l00242"></a><span class="lineno"><a class="line" href="classThread.html#affb34b8590eab79785627ae48cbd297d">  242</a></span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classThread.html#affb34b8590eab79785627ae48cbd297d">detach</a>() final {</div><div class="line"><a name="l00243"></a><span class="lineno">  243</span>&#160;            <a class="code" href="classThread.html#ad313ba812a7875c743dd0d37d565acfb">thread_</a>.detach();</div><div class="line"><a name="l00244"></a><span class="lineno">  244</span>&#160;        }</div><div class="line"><a name="l00245"></a><span class="lineno">  245</span>&#160;</div><div class="line"><a name="l00249"></a><span class="lineno"><a class="line" href="classThread.html#ac09e8b8ff4fb0a97315b5a501e722783">  249</a></span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classThread.html#ac09e8b8ff4fb0a97315b5a501e722783">yield</a>() final {</div><div class="line"><a name="l00250"></a><span class="lineno">  250</span>&#160;            <a class="code" href="classThread.html#a535df3b8fc4ff9ca48f5a6d561162a36">yield_</a> = <span class="keyword">true</span>;</div><div class="line"><a name="l00251"></a><span class="lineno">  251</span>&#160;        }</div><div class="line"><a name="l00252"></a><span class="lineno">  252</span>&#160;</div><div class="line"><a name="l00258"></a><span class="lineno"><a class="line" href="classThread.html#a86d1c278c0b9fea63037c437a909064f">  258</a></span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="classThread.html#a86d1c278c0b9fea63037c437a909064f">joinable</a>() const final {</div><div class="line"><a name="l00259"></a><span class="lineno">  259</span>&#160;            <span class="keywordflow">return</span> <a class="code" href="classThread.html#ad313ba812a7875c743dd0d37d565acfb">thread_</a>.joinable();</div><div class="line"><a name="l00260"></a><span class="lineno">  260</span>&#160;        }</div><div class="line"><a name="l00261"></a><span class="lineno">  261</span>&#160;</div><div class="line"><a name="l00267"></a><span class="lineno"><a class="line" href="classThread.html#a554185abbfacbcc4bf2e953cdddcbbba">  267</a></span>&#160;        <span class="keyword">virtual</span> std::thread::native_handle_type <span class="keyword">self</span>() <span class="keyword">final</span> {</div><div class="line"><a name="l00268"></a><span class="lineno">  268</span>&#160;            <span class="keywordflow">return</span> <a class="code" href="classThread.html#ad313ba812a7875c743dd0d37d565acfb">thread_</a>.native_handle();</div><div class="line"><a name="l00269"></a><span class="lineno">  269</span>&#160;        }</div><div class="line"><a name="l00270"></a><span class="lineno">  270</span>&#160;</div><div class="line"><a name="l00276"></a><span class="lineno"><a class="line" href="classThread.html#a19bc237f8a86727a5a4b516122fe20f6">  276</a></span>&#160;        <span class="keyword">virtual</span> std::string <a class="code" href="classThread.html#a19bc237f8a86727a5a4b516122fe20f6">getName</a>() const final {</div><div class="line"><a name="l00277"></a><span class="lineno">  277</span>&#160;            <span class="keywordflow">return</span> <a class="code" href="classThread.html#aa222eb32e5fc8f386d9fb018607acd9c">name_</a>;</div><div class="line"><a name="l00278"></a><span class="lineno">  278</span>&#160;        }</div><div class="line"><a name="l00279"></a><span class="lineno">  279</span>&#160;</div><div class="line"><a name="l00285"></a><span class="lineno"><a class="line" href="classThread.html#ae816904b2a3e248472813e17c2b12a71">  285</a></span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classThread.html#ae816904b2a3e248472813e17c2b12a71">setName</a>(<span class="keyword">const</span> std::string &amp; name)<span class="keyword">final</span> {</div><div class="line"><a name="l00286"></a><span class="lineno">  286</span>&#160;            this-&gt;<a class="code" href="classThread.html#aa222eb32e5fc8f386d9fb018607acd9c">name_</a> = name;</div><div class="line"><a name="l00287"></a><span class="lineno">  287</span>&#160;        }</div><div class="line"><a name="l00288"></a><span class="lineno">  288</span>&#160;</div><div class="line"><a name="l00295"></a><span class="lineno"><a class="line" href="classThread.html#ad7fd4dfa0edff93d118b2edf5ab7be2c">  295</a></span>&#160;        <span class="keyword">virtual</span> pid_t <a class="code" href="classThread.html#ad7fd4dfa0edff93d118b2edf5ab7be2c">getPid</a>() const final {</div><div class="line"><a name="l00296"></a><span class="lineno">  296</span>&#160;            <span class="keywordflow">return</span> <a class="code" href="classThread.html#a0c0878a96696bbb092a69bc2f1f812fd">currentPid_</a>;</div><div class="line"><a name="l00297"></a><span class="lineno">  297</span>&#160;        }</div><div class="line"><a name="l00298"></a><span class="lineno">  298</span>&#160;</div><div class="line"><a name="l00304"></a><span class="lineno">  304</span>&#160;        <span class="keyword">virtual</span> std::chrono::steady_clock::time_point</div><div class="line"><a name="l00305"></a><span class="lineno"><a class="line" href="classThread.html#a23de6830557bdbe18a0baf17db58aec6">  305</a></span>&#160;        <a class="code" href="classThread.html#a23de6830557bdbe18a0baf17db58aec6">getLastActiveTime</a>()const final {</div><div class="line"><a name="l00306"></a><span class="lineno">  306</span>&#160;            <span class="keywordflow">return</span> <a class="code" href="classThread.html#ae7ed71c6b1f7782ecd4186005fd70760">lastActiveTime_</a>;</div><div class="line"><a name="l00307"></a><span class="lineno">  307</span>&#160;        }</div><div class="line"><a name="l00308"></a><span class="lineno">  308</span>&#160;</div><div class="line"><a name="l00314"></a><span class="lineno"><a class="line" href="classThread.html#a231da16ab1825ee982c4aa43f78c1b22">  314</a></span>&#160;        <span class="keyword">virtual</span> std::thread::id <a class="code" href="classThread.html#a231da16ab1825ee982c4aa43f78c1b22">stdId</a>() final {</div><div class="line"><a name="l00315"></a><span class="lineno">  315</span>&#160;            <span class="keywordflow">return</span> <a class="code" href="classThread.html#ad313ba812a7875c743dd0d37d565acfb">thread_</a>.get_id();</div><div class="line"><a name="l00316"></a><span class="lineno">  316</span>&#160;        }</div><div class="line"><a name="l00317"></a><span class="lineno">  317</span>&#160;</div><div class="line"><a name="l00323"></a><span class="lineno"><a class="line" href="classThread.html#acb6c590deecea4778a855459f080060a">  323</a></span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="classThread.html#acb6c590deecea4778a855459f080060a">isIdle</a>() const final {</div><div class="line"><a name="l00324"></a><span class="lineno">  324</span>&#160;            <span class="keywordflow">return</span> <a class="code" href="classThread.html#a13aa04a60328060dec3a25b286c933a2">idle_</a>;</div><div class="line"><a name="l00325"></a><span class="lineno">  325</span>&#160;        }</div><div class="line"><a name="l00326"></a><span class="lineno">  326</span>&#160;</div><div class="line"><a name="l00332"></a><span class="lineno"><a class="line" href="classThread.html#ab4c718f3ca4aa7514c7e89e38f9da894">  332</a></span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="classThread.html#ab4c718f3ca4aa7514c7e89e38f9da894">isRunning</a>() final {</div><div class="line"><a name="l00333"></a><span class="lineno">  333</span>&#160;            <span class="keywordflow">return</span> !pthread_kill(<a class="code" href="classThread.html#ad313ba812a7875c743dd0d37d565acfb">thread_</a>.native_handle(), 0);</div><div class="line"><a name="l00334"></a><span class="lineno">  334</span>&#160;        }</div><div class="line"><a name="l00335"></a><span class="lineno">  335</span>&#160;</div><div class="line"><a name="l00341"></a><span class="lineno"><a class="line" href="classThread.html#a96661f80f5fbd26042a24eafd675cd91">  341</a></span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classThread.html#a96661f80f5fbd26042a24eafd675cd91">setPrio</a>(<span class="keywordtype">int</span> prio)<span class="keyword">final</span> {</div><div class="line"><a name="l00342"></a><span class="lineno">  342</span>&#160;            <a class="code" href="classThread.html#ada8c342b34fb001cfcf57619b7150840">prio_</a> = prio;</div><div class="line"><a name="l00343"></a><span class="lineno">  343</span>&#160;        }</div><div class="line"><a name="l00344"></a><span class="lineno">  344</span>&#160;</div><div class="line"><a name="l00350"></a><span class="lineno"><a class="line" href="classThread.html#a712ab58b9e89f458427b213b1197a666">  350</a></span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classThread.html#a712ab58b9e89f458427b213b1197a666">getPrio</a>()final {</div><div class="line"><a name="l00351"></a><span class="lineno">  351</span>&#160;            <span class="keywordflow">return</span> <a class="code" href="classThread.html#ada8c342b34fb001cfcf57619b7150840">prio_</a>;</div><div class="line"><a name="l00352"></a><span class="lineno">  352</span>&#160;        }</div><div class="line"><a name="l00353"></a><span class="lineno">  353</span>&#160;</div><div class="line"><a name="l00354"></a><span class="lineno">  354</span>&#160;    <span class="keyword">protected</span>:</div><div class="line"><a name="l00356"></a><span class="lineno"><a class="line" href="classThread.html#ada8c342b34fb001cfcf57619b7150840">  356</a></span>&#160;        <span class="keywordtype">int</span>                                    <a class="code" href="classThread.html#ada8c342b34fb001cfcf57619b7150840">prio_</a>;</div><div class="line"><a name="l00358"></a><span class="lineno"><a class="line" href="classThread.html#a0c0878a96696bbb092a69bc2f1f812fd">  358</a></span>&#160;        pid_t                                  <a class="code" href="classThread.html#a0c0878a96696bbb092a69bc2f1f812fd">currentPid_</a>{-1};</div><div class="line"><a name="l00360"></a><span class="lineno"><a class="line" href="classThread.html#aa222eb32e5fc8f386d9fb018607acd9c">  360</a></span>&#160;        std::string                            <a class="code" href="classThread.html#aa222eb32e5fc8f386d9fb018607acd9c">name_</a>;</div><div class="line"><a name="l00362"></a><span class="lineno"><a class="line" href="classThread.html#ad313ba812a7875c743dd0d37d565acfb">  362</a></span>&#160;        std::thread                            <a class="code" href="classThread.html#ad313ba812a7875c743dd0d37d565acfb">thread_</a>;</div><div class="line"><a name="l00364"></a><span class="lineno"><a class="line" href="classThread.html#a091bdad0a084b3f2c659f8cdd5369d53">  364</a></span>&#160;        std::atomic_bool                       <a class="code" href="classThread.html#a091bdad0a084b3f2c659f8cdd5369d53">stop_</a>{<span class="keyword">true</span>};</div><div class="line"><a name="l00366"></a><span class="lineno"><a class="line" href="classThread.html#a13aa04a60328060dec3a25b286c933a2">  366</a></span>&#160;        std::atomic_bool                       <a class="code" href="classThread.html#a13aa04a60328060dec3a25b286c933a2">idle_</a>{<span class="keyword">true</span>};</div><div class="line"><a name="l00368"></a><span class="lineno"><a class="line" href="classThread.html#a535df3b8fc4ff9ca48f5a6d561162a36">  368</a></span>&#160;        std::atomic_bool                       <a class="code" href="classThread.html#a535df3b8fc4ff9ca48f5a6d561162a36">yield_</a>{<span class="keyword">false</span>};</div><div class="line"><a name="l00370"></a><span class="lineno"><a class="line" href="classThread.html#ae7ed71c6b1f7782ecd4186005fd70760">  370</a></span>&#160;        std::chrono::steady_clock::time_point  <a class="code" href="classThread.html#ae7ed71c6b1f7782ecd4186005fd70760">lastActiveTime_</a>{std::chrono::steady_clock::now()};</div><div class="line"><a name="l00371"></a><span class="lineno">  371</span>&#160;</div><div class="line"><a name="l00372"></a><span class="lineno">  372</span>&#160;    <span class="keyword">protected</span>:</div><div class="line"><a name="l00376"></a><span class="lineno"><a class="line" href="classThread.html#a4cf09d1f62096dd4aed7a3ee06212b81">  376</a></span>&#160;        std::unique_ptr&lt;Functor_base&gt; <a class="code" href="classThread.html#a4cf09d1f62096dd4aed7a3ee06212b81">func_uptr_</a>;</div><div class="line"><a name="l00377"></a><span class="lineno">  377</span>&#160;</div><div class="line"><a name="l00378"></a><span class="lineno">  378</span>&#160;    <span class="keyword">public</span>:</div><div class="line"><a name="l00379"></a><span class="lineno">  379</span>&#160;        <a class="code" href="classThread.html#a66350772ff3af06962db113658a72ae3">Thread</a>(<span class="keyword">const</span> <a class="code" href="classThread.html">Thread</a>&amp;&amp;) = <span class="keyword">delete</span>;</div><div class="line"><a name="l00380"></a><span class="lineno">  380</span>&#160;        <a class="code" href="classThread.html">Thread</a>&amp; operator=(<span class="keyword">const</span> <a class="code" href="classThread.html">Thread</a>&amp;&amp;) = <span class="keyword">delete</span>;</div><div class="line"><a name="l00381"></a><span class="lineno">  381</span>&#160;        <a class="code" href="classThread.html#a66350772ff3af06962db113658a72ae3">Thread</a>(<span class="keyword">const</span> <a class="code" href="classThread.html">Thread</a>&amp;) = <span class="keyword">delete</span>;</div><div class="line"><a name="l00382"></a><span class="lineno">  382</span>&#160;        <a class="code" href="classThread.html">Thread</a>&amp; operator=(<span class="keyword">const</span> <a class="code" href="classThread.html">Thread</a>&amp;) = <span class="keyword">delete</span>;</div><div class="line"><a name="l00383"></a><span class="lineno">  383</span>&#160;};</div><div class="line"><a name="l00384"></a><span class="lineno">  384</span>&#160;</div><div class="line"><a name="l00385"></a><span class="lineno">  385</span>&#160;<span class="preprocessor">#endif </span><span class="comment">/* THREAD_HPP */</span><span class="preprocessor"></span></div><div class="ttc" id="structFunctor__t_html"><div class="ttname"><a href="structFunctor__t.html">Functor_t</a></div><div class="ttdef"><b>Definition:</b> functor_wrapper.hpp:16</div></div>
<div class="ttc" id="classThread_html_acb6c590deecea4778a855459f080060a"><div class="ttname"><a href="classThread.html#acb6c590deecea4778a855459f080060a">Thread::isIdle</a></div><div class="ttdeci">virtual bool isIdle() const final</div><div class="ttdoc">isIdle 查看线程是否空闲,使用的是类内部成员变量,与isRunning不同 </div><div class="ttdef"><b>Definition:</b> thread.hpp:323</div></div>
<div class="ttc" id="classThread_html_ab4c718f3ca4aa7514c7e89e38f9da894"><div class="ttname"><a href="classThread.html#ab4c718f3ca4aa7514c7e89e38f9da894">Thread::isRunning</a></div><div class="ttdeci">virtual bool isRunning() final</div><div class="ttdoc">isRunning 查看线程是否还在运行,使用pthread_kill向线程发信号 </div><div class="ttdef"><b>Definition:</b> thread.hpp:332</div></div>
<div class="ttc" id="classThread_html_a712ab58b9e89f458427b213b1197a666"><div class="ttname"><a href="classThread.html#a712ab58b9e89f458427b213b1197a666">Thread::getPrio</a></div><div class="ttdeci">virtual int getPrio() final</div><div class="ttdoc">getPrio 获取线程优先级 </div><div class="ttdef"><b>Definition:</b> thread.hpp:350</div></div>
<div class="ttc" id="classThread_html_a96661f80f5fbd26042a24eafd675cd91"><div class="ttname"><a href="classThread.html#a96661f80f5fbd26042a24eafd675cd91">Thread::setPrio</a></div><div class="ttdeci">virtual void setPrio(int prio) final</div><div class="ttdoc">setPrio 设置优先级 </div><div class="ttdef"><b>Definition:</b> thread.hpp:341</div></div>
<div class="ttc" id="classThread_html_a231da16ab1825ee982c4aa43f78c1b22"><div class="ttname"><a href="classThread.html#a231da16ab1825ee982c4aa43f78c1b22">Thread::stdId</a></div><div class="ttdeci">virtual std::thread::id stdId() final</div><div class="ttdoc">stdId 获取线程thread::id </div><div class="ttdef"><b>Definition:</b> thread.hpp:314</div></div>
<div class="ttc" id="classThread_html_a07b23d8d75300651cba3eb79652c77fd"><div class="ttname"><a href="classThread.html#a07b23d8d75300651cba3eb79652c77fd">Thread::join</a></div><div class="ttdeci">virtual void join() final</div><div class="ttdoc">join 释放线程资源,如果线程此时是空闲的,那么线程会退出 </div><div class="ttdef"><b>Definition:</b> thread.hpp:235</div></div>
<div class="ttc" id="classThread_html_aa222eb32e5fc8f386d9fb018607acd9c"><div class="ttname"><a href="classThread.html#aa222eb32e5fc8f386d9fb018607acd9c">Thread::name_</a></div><div class="ttdeci">std::string name_</div><div class="ttdoc">线程名前缀 </div><div class="ttdef"><b>Definition:</b> thread.hpp:360</div></div>
<div class="ttc" id="classThread_html_a7574ff300357f9d3193db03b83937eac"><div class="ttname"><a href="classThread.html#a7574ff300357f9d3193db03b83937eac">Thread::run</a></div><div class="ttdeci">virtual void run()</div><div class="ttdoc">run 重载实现操作 </div><div class="ttdef"><b>Definition:</b> thread.hpp:169</div></div>
<div class="ttc" id="classThread_html_a026b23628e1727050e864e00489c0baf"><div class="ttname"><a href="classThread.html#a026b23628e1727050e864e00489c0baf">Thread::~Thread</a></div><div class="ttdeci">virtual ~Thread()</div><div class="ttdoc">~Thread 析构函数 </div><div class="ttdef"><b>Definition:</b> thread.hpp:159</div></div>
<div class="ttc" id="classThread_html_a86d1c278c0b9fea63037c437a909064f"><div class="ttname"><a href="classThread.html#a86d1c278c0b9fea63037c437a909064f">Thread::joinable</a></div><div class="ttdeci">virtual bool joinable() const final</div><div class="ttdoc">joinable </div><div class="ttdef"><b>Definition:</b> thread.hpp:258</div></div>
<div class="ttc" id="classThread_html_a3a36451e02a15180624cdd88212cb1ba"><div class="ttname"><a href="classThread.html#a3a36451e02a15180624cdd88212cb1ba">Thread::start</a></div><div class="ttdeci">virtual void start() final</div><div class="ttdoc">start 开始执行线程,如果构造函数传入了Func, 那么重写的run方法不会执行 </div><div class="ttdef"><b>Definition:</b> thread.hpp:214</div></div>
<div class="ttc" id="classThread_html_a091bdad0a084b3f2c659f8cdd5369d53"><div class="ttname"><a href="classThread.html#a091bdad0a084b3f2c659f8cdd5369d53">Thread::stop_</a></div><div class="ttdeci">std::atomic_bool stop_</div><div class="ttdoc">线程停止标志 </div><div class="ttdef"><b>Definition:</b> thread.hpp:364</div></div>
<div class="ttc" id="classThread_html_a4cf09d1f62096dd4aed7a3ee06212b81"><div class="ttname"><a href="classThread.html#a4cf09d1f62096dd4aed7a3ee06212b81">Thread::func_uptr_</a></div><div class="ttdeci">std::unique_ptr&lt; Functor_base &gt; func_uptr_</div><div class="ttdoc">函数封装 </div><div class="ttdef"><b>Definition:</b> thread.hpp:376</div></div>
<div class="ttc" id="classThread_html_a23de6830557bdbe18a0baf17db58aec6"><div class="ttname"><a href="classThread.html#a23de6830557bdbe18a0baf17db58aec6">Thread::getLastActiveTime</a></div><div class="ttdeci">virtual std::chrono::steady_clock::time_point getLastActiveTime() const final</div><div class="ttdoc">getLastActiveTime 上一次活跃时间 </div><div class="ttdef"><b>Definition:</b> thread.hpp:305</div></div>
<div class="ttc" id="classThread_html_affb34b8590eab79785627ae48cbd297d"><div class="ttname"><a href="classThread.html#affb34b8590eab79785627ae48cbd297d">Thread::detach</a></div><div class="ttdeci">virtual void detach() final</div><div class="ttdoc">detach 释放线程,如果线程此时是空闲的,那么线程会退出 </div><div class="ttdef"><b>Definition:</b> thread.hpp:242</div></div>
<div class="ttc" id="classThread_html_a61efca5f0beb62628c515fb7cdef7e08"><div class="ttname"><a href="classThread.html#a61efca5f0beb62628c515fb7cdef7e08">Thread::Thread</a></div><div class="ttdeci">Thread(FunctionType f, const std::string &amp;name=&quot;&quot;, int pro=20)</div><div class="ttdoc">Thread 构造函数 </div><div class="ttdef"><b>Definition:</b> thread.hpp:153</div></div>
<div class="ttc" id="classThread_html_ac09e8b8ff4fb0a97315b5a501e722783"><div class="ttname"><a href="classThread.html#ac09e8b8ff4fb0a97315b5a501e722783">Thread::yield</a></div><div class="ttdeci">virtual void yield() final</div><div class="ttdoc">yield 让出时间片 </div><div class="ttdef"><b>Definition:</b> thread.hpp:249</div></div>
<div class="ttc" id="classThread_html_ae7ed71c6b1f7782ecd4186005fd70760"><div class="ttname"><a href="classThread.html#ae7ed71c6b1f7782ecd4186005fd70760">Thread::lastActiveTime_</a></div><div class="ttdeci">std::chrono::steady_clock::time_point lastActiveTime_</div><div class="ttdoc">上次活跃时间 </div><div class="ttdef"><b>Definition:</b> thread.hpp:370</div></div>
<div class="ttc" id="classThreadPoolExecutor_html"><div class="ttname"><a href="classThreadPoolExecutor.html">ThreadPoolExecutor</a></div><div class="ttdoc">线程池基本实现,每个线程都有一个任务队列 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:45</div></div>
<div class="ttc" id="classThread_html_a430059e402325caaf1ed185fb520c9d2"><div class="ttname"><a href="classThread.html#a430059e402325caaf1ed185fb520c9d2">Thread::sptr</a></div><div class="ttdeci">std::shared_ptr&lt; Thread &gt; sptr</div><div class="ttdoc">std::shared_ptr&lt;Thread&gt;别名 </div><div class="ttdef"><b>Definition:</b> thread.hpp:127</div></div>
<div class="ttc" id="classThread_html_a038819a1ef7bb4e50ae580d477f1a3b0"><div class="ttname"><a href="classThread.html#a038819a1ef7bb4e50ae580d477f1a3b0">Thread::Thread</a></div><div class="ttdeci">Thread(const std::string &amp;name=&quot;&quot;, int pro=20)</div><div class="ttdoc">Thread 构造函数 </div><div class="ttdef"><b>Definition:</b> thread.hpp:142</div></div>
<div class="ttc" id="classThread_html"><div class="ttname"><a href="classThread.html">Thread</a></div><div class="ttdoc">C++11线程封装类,包含更丰富功能 </div><div class="ttdef"><b>Definition:</b> thread.hpp:122</div></div>
<div class="ttc" id="classThread_html_ad7fd4dfa0edff93d118b2edf5ab7be2c"><div class="ttname"><a href="classThread.html#ad7fd4dfa0edff93d118b2edf5ab7be2c">Thread::getPid</a></div><div class="ttdeci">virtual pid_t getPid() const final</div><div class="ttdoc">getCurrentPid 获取Linux底层线程id, start之后才有效,-1表示线程已经结束 </div><div class="ttdef"><b>Definition:</b> thread.hpp:295</div></div>
<div class="ttc" id="classThread_html_ad313ba812a7875c743dd0d37d565acfb"><div class="ttname"><a href="classThread.html#ad313ba812a7875c743dd0d37d565acfb">Thread::thread_</a></div><div class="ttdeci">std::thread thread_</div><div class="ttdoc">线程 </div><div class="ttdef"><b>Definition:</b> thread.hpp:362</div></div>
<div class="ttc" id="classThread_html_a535df3b8fc4ff9ca48f5a6d561162a36"><div class="ttname"><a href="classThread.html#a535df3b8fc4ff9ca48f5a6d561162a36">Thread::yield_</a></div><div class="ttdeci">std::atomic_bool yield_</div><div class="ttdoc">让出时间片标志 </div><div class="ttdef"><b>Definition:</b> thread.hpp:368</div></div>
<div class="ttc" id="classThread_html_a19bc237f8a86727a5a4b516122fe20f6"><div class="ttname"><a href="classThread.html#a19bc237f8a86727a5a4b516122fe20f6">Thread::getName</a></div><div class="ttdeci">virtual std::string getName() const final</div><div class="ttdoc">getName 得到线程名称 </div><div class="ttdef"><b>Definition:</b> thread.hpp:276</div></div>
<div class="ttc" id="classThread_html_a66350772ff3af06962db113658a72ae3"><div class="ttname"><a href="classThread.html#a66350772ff3af06962db113658a72ae3">Thread::Thread</a></div><div class="ttdeci">Thread(int pro)</div><div class="ttdoc">Thread 构造函数 </div><div class="ttdef"><b>Definition:</b> thread.hpp:134</div></div>
<div class="ttc" id="classThread_html_a0c0878a96696bbb092a69bc2f1f812fd"><div class="ttname"><a href="classThread.html#a0c0878a96696bbb092a69bc2f1f812fd">Thread::currentPid_</a></div><div class="ttdeci">pid_t currentPid_</div><div class="ttdoc">-1表明线程已经执行完任务,unix底层的线程已经不存在了 </div><div class="ttdef"><b>Definition:</b> thread.hpp:358</div></div>
<div class="ttc" id="classThread_html_ae816904b2a3e248472813e17c2b12a71"><div class="ttname"><a href="classThread.html#ae816904b2a3e248472813e17c2b12a71">Thread::setName</a></div><div class="ttdeci">virtual void setName(const std::string &amp;name) final</div><div class="ttdoc">setName 设置线程名称 </div><div class="ttdef"><b>Definition:</b> thread.hpp:285</div></div>
<div class="ttc" id="classThread_html_a13aa04a60328060dec3a25b286c933a2"><div class="ttname"><a href="classThread.html#a13aa04a60328060dec3a25b286c933a2">Thread::idle_</a></div><div class="ttdeci">std::atomic_bool idle_</div><div class="ttdoc">线程空闲标志 </div><div class="ttdef"><b>Definition:</b> thread.hpp:366</div></div>
<div class="ttc" id="classThread_html_ada8c342b34fb001cfcf57619b7150840"><div class="ttname"><a href="classThread.html#ada8c342b34fb001cfcf57619b7150840">Thread::prio_</a></div><div class="ttdeci">int prio_</div><div class="ttdoc">线程优先级 </div><div class="ttdef"><b>Definition:</b> thread.hpp:356</div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者 &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>
